<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#0A348B" ref="tabs" :list="list" :current="current" @change="change"
					:is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order" @click="toDetail(item)" v-for="(item,i) in orderList[0]" :key="i">
								<view class="top">
									<view class="left">
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;"></text>
										<text>{{item.pdCharginOrder.deviceCode}}</text> <text>(充电站编号 )</text>
									</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;">进行中</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;">充满即停/设备断电</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;">余额不足</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;">充电完成</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;">自动关闭</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;">手动关闭</view>
								</view>
								<view class="item">
									<view> <text>电站地址：</text>{{item.pdCharginOrder.charginAddress}}</view>
									<view> <text>订单时间：</text>{{item.pdCharginOrder.startTime}}</view>
									<view> <text>充电端口：</text>{{item.pdCharginOrder.portNum}} 号</view>
									<view> <text>实际使用：</text>{{item.pdCharginOrder.coinsConsume}} PdConin</view>
								</view>
							</view>
							<view style="margin-top: 30rpx;">
								<u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order" @click="toDetail(item)" v-for="(item,i) in orderList[1]" :key="i">
								<view class="top">
									<view class="left">
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;"></text>
										<text>{{item.pdCharginOrder.deviceCode}}</text> <text>(充电站编号 )</text>
									</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;">进行中</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;">充满即停/设备断电</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;">余额不足</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;">充电完成</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;">自动关闭</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;">手动关闭</view>
								</view>
								<view class="item">
									<view> <text>电站地址：</text>{{item.pdCharginOrder.charginAddress}}</view>
									<view> <text>订单时间：</text>{{item.pdCharginOrder.startTime}}</view>
									<view> <text>充电端口：</text>{{item.pdCharginOrder.portNum}} 号</view>
									<view> <text>实际使用：</text>{{item.pdCharginOrder.coinsConsume}} PdConin</view>
								</view>
						
							</view>
							<view style="margin-top: 30rpx;">
								<u-loadmore :status="loadStatus[1]" bgColor="#f2f2f2"></u-loadmore>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;">
						<view class="page-box">
							<view class="order" @click="toDetail(item)" v-for="(item,i) in orderList[2]" :key="i">
								<view class="top">
									<view class="left">
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;"></text>
										<text class="radistext" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;"></text>
										<text>{{item.pdCharginOrder.deviceCode}}</text> <text>(充电站编号 )</text>
									</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 0" style="background-color: #48D499;">进行中</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 1" style="background-color: #48D499;">充满即停/设备断电</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 2" style="background-color: #FABA30;">余额不足</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 3" style="background-color: #48D499;">充电完成</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 4" style="background-color: #ED8C8C;">自动关闭</view>
									<view class="right" v-if="item.pdCharginOrder.chargingStatus == 5" style="background-color: #ED8C8C;">手动关闭</view>
								</view>
								<view class="item">
									<view> <text>电站地址：</text>{{item.pdCharginOrder.charginAddress}}</view>
									<view> <text>订单时间：</text>{{item.pdCharginOrder.startTime}}</view>
									<view> <text>充电端口：</text>{{item.pdCharginOrder.portNum}} 号</view>
									<view> <text>支付口袋币：</text>{{item.pdCharginOrder.coins}} PdConin</view>
								</view>
						
							</view>
							<view style="margin-top: 30rpx;">
								<u-loadmore :status="loadStatus[2]" bgColor="#f2f2f2"></u-loadmore>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
		
			</swiper>
		</view>
	</view>
</template>

<script>
	import {findCharginOrderList} from '../../api/charging'
	export default {
		data() {
			return {
				orderList: [
					[],
					[],
					[],
					[]
				],
				dataList: [],
				list: [{
						name: '全部'
					},
					{
						name: '完成充电'
					},
					{
						name: '正在充电'
					}
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['loadmore', 'loadmore', 'loadmore', 'loadmore'],
				query:{
					pageNo:1,
					pageSize:10,
				}
			};
		},
		onLoad() {
            this.query.pageNo = 1
            this.query.pageSize = 10
			this.getOrderList(0);
			// this.getOrderList(1);
			// this.getOrderList(2);
			// this.getOrderList(3);
		},
		onShow() {
            this.query.pageNo = 1
            this.query.pageSize = 10
			
			this.getOrderList(0);
		},
		computed: {
			// 价格小数
			priceDecimal() {
				return val => {
					if (val !== parseInt(val)) return val.slice(-2);
					else return '00';
				};
			},
			// 价格整数
			priceInt() {
				return val => {
					if (val !== parseInt(val)) return val.split('.')[0];
					else return val;
				};
			}
		},
		methods: {
			toDetail(row){
				uni.navigateTo({
					url:'./order-detail?orderId='+row.pdCharginOrder.id
				})
			},
			reachBottom() {
				console.log(this.current,'第几个')
				
				if(this.current == 0){
					this.query.orderStatus = null
				}else if(this.current == 1){
					this.query.orderStatus = 2
				}else if(this.current == 2){
					this.query.orderStatus = 1
				}

				
					this.loadStatus.splice(this.current,1,"loading")
				setTimeout(() => {
					this.query.pageNo =  this.query.pageNo + 1
					findCharginOrderList(this.query).then(res => {
						
						let newslist  = res.result.records
						
						let list = this.orderList[this.current]
						
						
						list.push.apply(list,newslist)
						console.log('原有的数组',this.list)
						
						if(res.result.records.length == 0){
							this.loadStatus.splice(this.current,1,"nomore")
						}else{
							this.loadStatus.splice(this.current,1,"loadmore")
						}
						
					})
					
					
					
				}, 1000)

			},
			// 页面数据
			async getOrderList(idx) {
				console.log(idx,'第几个')

				await findCharginOrderList(this.query).then(res => {
					console.log(res.result.records,'数据')
					this.orderList[idx] = res.result.records
				})
				this.loadStatus.splice(this.current, 1, "loadmore")
			},

			// tab栏切换
			change(index) {
				console.log(index)
				this.query.pageNo =  1
				if(index == 0){
					this.query.orderStatus = null
				}else if(index == 1){
					this.query.orderStatus = 2
				}else if(index == 2){
					this.query.orderStatus = 1
				}
				this.swiperCurrent = index;
				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			}
		}
	};
</script>


<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>
<style lang="scss" scoped>
	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;
			margin: 20rpx 0;
			.left {
				display: flex;
				align-items: center;
				
				.radistext{
					width: 16rpx;
					height: 16rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}
				

				text:nth-child(2) {
					font-size: 32rpx;
					font-weight: 400;
					color: #000000;
					margin-right: 10rpx;
				}

				text:nth-child(3) {
					font-size: 24rpx;
					font-weight: 400;
					color: #cbcbcb;
				}
			}

			.right {
				display: flex;
				align-items: center;
				color: #ffffff;
				border-radius: 11rpx;
				font-weight: 400;
				font-size: 24rpx;
				padding: 10rpx 20rpx;
			}
		}

		.item {
			view {
				margin: 10rpx 0;
			}

			font-weight: 400;
			color: #696969;
			font-size: 26rpx;

			text {
				color: #aaaaaa;
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg,
					rgba(249, 116, 90, 1) 0%,
					rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>
